package servlet.admin.characters;

import service.CharacterService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet( name = "AdminCharactersUpdateServlet")
public class AdminCharactersUpdateServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cname= new String(request.getParameter("cname").getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
        Integer characterID=Integer.parseInt(request.getParameter("characterID"));

        CharacterService service=new CharacterService();
        service.update(characterID,cname);
        request.getServletContext().getRequestDispatcher("/AdminCharactersServlet?cp=characters").forward(request, response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
